package com.snake.design.pe.prototype;

/**
 * 
 * @author fengx00 原型模式只要实现Cloneable接口 写个方法调用下clone方法返回该对象即可
 * 
 *         使用原型模式创建对象比直接new一个对象在性能上要好的多，因为Object类的clone方法是一个本地方法，它直接操作内存中的二进制流，
 *         特别是复制大对象时，性能的差别非常明显
 * 
 */
public class Computer implements Cloneable {
	private Double price;
	private String name;

	public Computer(Double price, String name) {
		super();
		this.price = price;
		this.name = name;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Computer clone() {
		Computer co = null;
		try {
			co = (Computer) super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return co;
	}

	public static void main(String[] args) {
		Computer c = new Computer(12.1, "apple");
		Computer clone = c.clone();
		System.out.println(clone.getName() + "----" + clone.getPrice());

	}
}
